package no;
//javabean的属性名不能以大写开头，类名也不能大写开头
//jsp+javabean的类
public class ComplexNumber {
    private double realPart1;
    private double imagePart1;
    private double realPart2;
    private double imagePart2;
    private String operation;
    private double realans;
    private double imageans;

    public double getRealPart1() {
        return realPart1;
    }

    public void setRealPart1(double realPart1) {
        this.realPart1 = realPart1;
    }

    public double getImagePart1() {
        return imagePart1;
    }

    public void setImagePart1(double imagePart1) {
        this.imagePart1 = imagePart1;
    }

    public double getRealPart2() {
        return realPart2;
    }

    public void setRealPart2(double realPart2) {
        this.realPart2 = realPart2;
    }

    public double getImagePart2() {
        return imagePart2;
    }

    public void setImagePart2(double imagePart2) {
        this.imagePart2 = imagePart2;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public double getRealans() {
        return realans;
    }

    public void setRealans(double realans) {
        this.realans = realans;
    }

    public double getImageans() {
        return imageans;
    }

    public void setImageans(double imageans) {
        this.imageans = imageans;
    }

    public void Calc(){
        switch (operation){
            case "+":
                realans=realPart1+realPart2;
                imageans=imagePart1+imagePart2;
                break;
            case "-":
                realans=realPart1-realPart2;
                imageans=imagePart1-imagePart2;
                break;
            case "*":
                realans=(realPart1*realPart2)-(imagePart1*imagePart2);
                imageans=(imagePart1*realPart2)+(realPart1*imagePart2);
                break;
            case "/":
                realans=(realPart1*realPart2+imagePart1*imagePart2)/(imagePart1*imagePart1+imagePart2*imagePart2);
                imageans=(imagePart1*realPart2-realPart1*imagePart2)/(imagePart1*imagePart1+imagePart2*imagePart2);
        }
        setRealans(realans);
        setImageans(imageans);
    }
}
